import React from 'react';
import { Router, Route, Link, browserHistory } from 'react-router';

import SDRouter from './SDRouter.js';
import Home from '../single/pages/Home';
import App from '../single/widgets/App';
import Debug from '../single/widgets/Debug';
import NotMatch from '../single/widgets/NotMatch';
import RegSchedule from '../single/pages/RegSchedule';
import Individual from '../single/pages/Individual';
import EditorContainer from '../single/pages/EditorContainer';
import ModelDetail from '../single/pages/ModelDetail';
import EmbedViewerContainer from '../single/pages/EmbedViewerContainer';
import IndividualSetting from '../single/pages/IndividualSetting';

import ProductionDetail from '../single/pages/ProductionDetail';

import ProductionDetailViewer from '../single/pages/ProductionDetailViewer';

import Error from '../single/pages/Error';

import Frame from '../single/widgets/Frame';
import FrameDark from '../single/widgets/FrameDark';


//https://github.com/reactjs/react-router/blob/master/docs/guides/RouteConfiguration.md

var routes = {
    path: '/:lang',
    component: App,
    indexRoute: {
        component: Home
    },
    childRoutes: [{
        path: 'frame',
        component: Frame,

        indexRoute: {
            onEnter: ({ params }, replace) => { window.location.href = `/${params.lang}`; },
            component: Home
        },
        childRoutes: [{
            path: 'productions/:uuid',
            component: ProductionDetail,

        }, {
            path: 'productions/:uuid/embed_url',
            component: EmbedViewerContainer,

        }, {
            path: 'contents/:uuid',
            component: ModelDetail,

        }, {
            path: 'contents/:uuid/editor',
            component: EditorContainer,
        }, {
            path: 'contents/:uuid/embed_url',
            component: EmbedViewerContainer,
        }, {
            path: 'individual',
            component: Individual,
        }, {
            path: 'settings',
            component: IndividualSetting,
        }, {
            path: ':authenticate_type/authenticate/:token',
            component: RegSchedule,
        }, {
            path: 'error/:type',
            component: Error,
        }, {
            path: 'single_debug',
            component: Debug,
            childRoutes: SDRouter
        }]
    }, {
        path: 'frame/dark',
        component: FrameDark,
        childRoutes: [{
            path: 'single_debug',
            component: Debug,
            childRoutes: SDRouter
        }]
    }, {
        path: 'product',
        component: Home,
    }, {
        path: 'support',
        component: Home,
    }, {
        path: 'about',
        component: Home,
    }, {
        path: '*',
        component: Error,
    }]
};


export default (() => (
    <Router history={browserHistory} routes={routes} />
));
